<?php

namespace backend\models;

use frontend\models\UserFavourite;
use Yii;
use backend\models\BuildCity;

/**
 * This is the model class for table "build_type".
 *
 * @property integer $id
 * @property integer $bid
 * @property string $title
 * @property integer $img_small_id
 * @property integer $img_thumb_id
 * @property integer $img_url_id
 * @property string $tz_img_list
 */
class BuildType extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
	public $image_upload;
    public static function tableName()
    {
        return 'build_type';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['bid', 'img_small_id', 'img_thumb_id', 'img_url_id'], 'integer'],
            [['title', 'tz_img_list'], 'string', 'max' => 255],
            [['bid','title'],'required'],
            [['image_upload'], 'image','extensions' => 'png,jpg,jpeg,gif,bmp','maxWidth'=>'800','maxHeight'=>'5000',
            'overWidth'=>'宽必须低于800像素','overHeight'=>'高必须低于5000像素'],
            
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'bid' => Yii::t('app','Bids'),
            'title' => Yii::t('app','Build Type Title'),
            'img_small_id' => Yii::t('app','Build Type Img'),
            'img_thumb_id' => Yii::t('app','Build Type Img'),
            'img_url_id' => Yii::t('app','Build Type Img'),
            'tz_img_list' => Yii::t('app','Build Type TZ Img'),
            'image_upload'=>Yii::t('app','Build City Image Upload')
        ];
    }
    public function getBuildCity(){
    	return $this->hasOne(BuildCity::className(), ['id' => 'bid']);
    }
    public function getBuildName(){
    	return $this->hasOne(BuildCity::className(), ['id'=>'bid']);
    }
    public function getImgL()
    {
        return $this->hasOne(Image::className(), ['id' => 'img_url_id']);
    }
    public function getFavo()
    {
        $uid = Yii::$app->getUser()->getId();
        return $this->hasOne(UserFavourite::className(), ['type_id' => 'id'])->andWhere(['user_favorite.type' => 3, 'user_favorite.uid' => $uid]);
    }
}
